// set path 
gl path "~/"

use "$path/Replication/issues_descriptive.dta", clear

gen ind = .
local i = 1
foreach issue in aggregation cemetery charter current_expenses liquor parks safety roads school senior_children zoning misc {
	local j = 1
	foreach locality in county city township school village {
		replace ind = `locality'_`issue'_g == 1
		qui sum ind
		di `i'
		di `j'
		local m`i'`j' = r(mean)
		replace ind = (`locality'_aggregation_g == 1) | (`locality'_cemetery_g == 1) | (`locality'_charter_g == 1) | ///
		(`locality'_current_expenses_g == 1) | (`locality'_liquor_g == 1) | (`locality'_parks_g == 1) | ///
		(`locality'_safety_g == 1) | (`locality'_roads_g == 1) | (`locality'_school_g == 1) | ///
		(`locality'_senior_children_g == 1) | (`locality'_zoning_g == 1) | (`locality'_misc_g == 1) 
		qui sum ind
		local m13`j' = r(mean)
		local j = `j' + 1
	}
	// get total here
	replace ind = (county_`issue'_g == 1) | (city_`issue'_g == 1) | (township_`issue'_g == 1) | (school_`issue'_g == 1) | (village_`issue'_g == 1)
	qui sum ind
	di `i'
	local t`i' = r(mean)
	local i = `i' + 1
}

egen total_ind = max(township_safety_g-county_misc_g)
qui sum total_ind
local t13 = r(mean)

quietly {
	cap log close
	set linesize 255
	log using "$path/Replication/Table3.tex", text replace
	
	noisily dis "\begin{table}[t]"
	noisily dis "\centering"
	noisily dis "\small"
	noisily dis "\caption{\textbf{Types of Local Issues Voted on in General Elections, Ohio, 2013-2017}"

	noisily dis "\label{tab:issues_descriptive}}"
	noisily dis "\begin{tabular}{lcccccc}"
	noisily dis "\toprule \toprule"
	
	noisily dis " &  \multicolumn{6}{c}{\% Voters with Issue on Ballot in General Election} \\\cline{2-7}\\[-2mm]"
	noisily dis " Issue Type & County & City & Township & School & Village & Total \\"
	noisily dis "\midrule"
	noisily dis " Aggregation &  " %4.3f `m11' " &  " %4.3f `m12' " &  " %4.3f `m13' " &  " %4.3f `m14' " &  " %4.3f `m15' " &  " %4.3f `t1' "  \\"
	noisily dis " Cemetery &  " %4.3f `m21' " &  " %4.3f `m22' " &  " %4.3f `m23' " &  " %4.3f `m24' " &  " %4.3f `m25' " &  " %4.3f `t2' "  \\"
	noisily dis " Charter &  " %4.3f `m31' " &  " %4.3f `m32' " &  " %4.3f `m33' " &  " %4.3f `m34' " &  " %4.3f `m35' " &  " %4.3f `t3' "  \\"
	noisily dis " Current Expenses &  " %4.3f `m41' " &  " %4.3f `m42' " &  " %4.3f `m43' " &  " %4.3f `m44' " &  " %4.3f `m45' " &  " %4.3f `t4' "  \\"
	noisily dis " Liquor &  " %4.3f `m51' " &  " %4.3f `m52' " &  " %4.3f `m53' " &  " %4.3f `m54' " &  " %4.3f `m55' " &  " %4.3f `t5' "  \\"
	noisily dis " Parks &  " %4.3f `m61' " &  " %4.3f `m62' " &  " %4.3f `m63' " &  " %4.3f `m64' " &  " %4.3f `m65' " &  " %4.3f `t6' "  \\"
	noisily dis " Public Safety &  " %4.3f `m71' " &  " %4.3f `m72' " &  " %4.3f `m73' " &  " %4.3f `m74' " &  " %4.3f `m75' " &  " %4.3f `t7' "  \\"
	noisily dis " Roads &  " %4.3f `m81' " &  " %4.3f `m82' " &  " %4.3f `m83' " &  " %4.3f `m84' " &  " %4.3f `m85' " &  " %4.3f `t8' "  \\"
	noisily dis " School &  " %4.3f `m91' " &  " %4.3f `m92' " &  " %4.3f `m93' " &  " %4.3f `m94' " &  " %4.3f `m95' " &  " %4.3f `t9' "  \\"
	noisily dis " Seniors and Children &  " %4.3f `m101' " &  " %4.3f `m102' " &  " %4.3f `m103' " &  " %4.3f `m104' " &  " %4.3f `m105' " &  " %4.3f `t10' "  \\"
	noisily dis " Zoning &  " %4.3f `m111' " &  " %4.3f `m112' " &  " %4.3f `m113' " &  " %4.3f `m114' " &  " %4.3f `m115' " &  " %4.3f `t11' "  \\"
	noisily dis " Miscellaneous &  " %4.3f `m121' " &  " %4.3f `m122' " &  " %4.3f `m123' " &  " %4.3f `m124' " &  " %4.3f `m125' " &  " %4.3f `t12' "  \\"
	noisily dis "\midrule"
	noisily dis " Any & " %4.3f `m131' " &  " %4.3f `m132' " &  " %4.3f `m133' " &  " %4.3f `m134' " &  " %4.3f `m135' " &  " %4.3f `t13' "  \\"

	noisily dis "\bottomrule \bottomrule"
	noisily dis "\multicolumn{7}{p{.8\textwidth}}{\footnotesize The table shows the percentage of registered voters that have each issue "
	noisily dis "type appear on their general election ballot, separated by locality.  The total column shows the percentage of registered "
	noisily dis "voters that have that issue type appear on their general election ballot in any of their registered localities.  "
	noisily dis "Any is whether the voter had any issue type, including miscellaenous, appear on their general election ballot.  "
	noisily dis "We review our coding of local issue types in the Appendix. "
	noisily dis "}"
	noisily dis "\end{tabular}"
	noisily dis "\end{table}"
	
	log off
	
}
